﻿<%@ Control Language="C#" ClassName="RatingLabel" %>
<script runat="server">
    private float rating;
    private int height = 24;

    public decimal Rating
    {
        get { return (decimal) rating; }
        set
        {
            if (value < 0)
                throw new ArgumentOutOfRangeException("rating不可为负数");
            rating = (float) value;
            label.Attributes["title"] = "Rating " + rating;
            //TODO:测试rating为小数时的表现。

            label.Controls.Clear();

            int roundedValue = (int)Math.Round(rating, 0, MidpointRounding.AwayFromZero);

            for (int i = 0; i < roundedValue; i++)
            {
                HtmlGenericControl img = new HtmlGenericControl();
                img.TagName = "img";
                img.Attributes["src"] = ResolveClientUrl("~/Images/star.jpg");
                img.Attributes["alt"] = "Star";
                img.Attributes["height"] = height.ToString();
                label.Controls.Add(img);
            }
        }
    }

    public int Height
    {
        get { return height; }
        set { height = value; }
    }

</script>
<span id="label" runat="server"/>